package com.dongdong.controller;

import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
import com.dongdong.result.*;

import com.dongdong.service.TypeTemplateService;



import com.dongdong.vo.TypeTemplateVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("typetemplate")
public class TypeTemplateController {

    @Autowired
    private TypeTemplateService typeTemplateService;


    @PostMapping("/findTypeTemplatePage")
    public Result findTypeTemplatePage(@RequestBody PageBean<TypeTemplateVO> pageBean){
        PageResult<TypeTemplateVO> result = typeTemplateService.findTypeTemplatePage(pageBean);
        return Result.OK().setData(result);
    }
//增加
    @PostMapping("add")
    public Result add(@RequestBody TypeTemplateVO typeTemplateVO){
        typeTemplateService.insert(typeTemplateVO);
        return new Result(ResultConstant.SUCCESS_CODE, ResultConstant.SUCCESS_MSG); //4：操作成功
    }

//回显
    @GetMapping("selectbyid")
    public Result selectbyid(@RequestParam Long id){
        TypeTemplateVO typeTemplateVO= typeTemplateService.selectbyid(id);
        return Result.OK().setData(typeTemplateVO);
    }
    //修改
    @PostMapping("update")
    public Result update(@RequestBody TypeTemplateVO typeTemplateVO){
        typeTemplateService.update(typeTemplateVO);
        return Result.OK();
    }
//删除
    @GetMapping("deletebyid")
    public Result deletebyid(@RequestParam Long id){
        typeTemplateService.deletebyid(id);
        return Result.RESPONSE(ResultEnums.SUCCESS);
    }

    //批量删除
    @GetMapping("deleteCheckids")
    public Result  deleteCheckids(@RequestParam Integer[] ids) {
        int i = typeTemplateService.deletebyids(ids);
        System.out.println(i);
        if (i <1) {
            return Result.OK();

        }
        return Result.ERROR();

    }

}
